<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/jsp/component/common.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" ></meta>
    <title>骨松档案新增病人信息</title>
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap.min.css" type="text/css" type="text/css">
    <link rel="stylesheet" href="${frames}/css/lib/bootstrap-datetimepicker.min.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/base/base.css" type="text/css">
    <%--<link rel="stylesheet" href="${newframe}/css/common.css" type="text/css">--%>
    <link rel="stylesheet" href="${frames}/css/picker.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/select2.min.css" type="text/css">
    <link rel="stylesheet" href="${newframe}/css/beautify-time.css" type="text/css">
    <link rel="stylesheet" href="${assets}/css/views/department/addDepartment.css">
    <%@ include file="/WEB-INF/jsp/component/commonBottom.jsp" %>
    <script src="${frames}/laydate/laydate.dev.js"></script>
    <script src="${assets}/bootstrapValidator/js/bootstrapValidator.js"></script>
    <script src="${assets}/bootstrapValidator/js/language/zh_CN.js"></script>
    <script src="${newframe}/js/select2.full.zh.js"></script>
    <link rel="stylesheet" href="../assets/css/select-bootstrap.css">
    <script src="../assets/js/select-bootstrap.js"></script>
    <!--[if IE 8]>
    <link rel="stylesheet" href="${newframe}/css/base/IE8.css" type="text/css"/>
    <![endif]-->
    <style>
        .select2-container {
            width: 100% !important;
        }
        .btn-myStyle{
            background-color: #2c3e50;
            color:#fff;
        }
        .btn{
            width:100px;
            line-height:15px;
            background:#35acfd;
            color:white;
        }
        .form-horizontal .control-label {
            padding-top:0;
            text-align: left;
        }
        h1{
            font-family: MicrosoftYaHei;
            font-size: 20px;
            font-weight: normal;
            color: #2a3137;
            margin-bottom: 26px;
            float: left;
            margin-top:0 !important
        }
        .dropdown-toggle{
            width:100%;
        }
        select{
            border:1px solid #d0d0d0;
            font:15px/30px '微软雅黑';
            color:black;
            text-indent:1rem;
        }
        .header{
            width:100%;
            overflow:hidden;
        }
        /*.btn-primary{*/
        /*background-color: #000 !important;*/
        /*}*/
        .bootstrap-select{
            padding:0 !important
        }
        .dropdown-toggle{
            background:white;
        }
        .filter-option{
            color:black;
        }
        .required{
            background: #f2eed5 !important;
        }
        span.remark{
            color: red;
            margin-left: 8px;
            display: inline-block;
            font-size: 20px;
        }
        .mgr{
            margin-right:8px ;
        }
    </style>
    <script>
        $(document).ready(function(){
            formValidator();
            var typeList = [
                {
                    id:'1',
                    name:'高血压人群',
                },
                {
                    id:'2',
                    name:'糖尿病人群',
                },
                {
                    id:'3',
                    name:'高血脂人群',
                },
                {
                    id:'4',
                    name:'骨松人群'
                }
            ]
            console.log(location.search)
            var url = location.search.split('?')[1].split('=')[1]
            var options = $('#diseasesType option')
            if( url != '' ){
                if (url[0] === '1') {
                    options[0].selected = true
                } else if (url[0] === '2') {
                    options[1].selected = true
                } else if (url[0] === '3') {
                    options[2].selected = true
                } else if (url[0] === '4') {
                    options[3].selected = true
                }else if (url[0] === '5') {
                    options[4].selected = true
                }
            }else{
                $(function() {
                    $("#diseasesType").selectpicker({
                        noneSelectedText: '请选择人群' //默认显示内容  
                    });
                });
            }
        });
        function formValidator() {
            var arr = []
            $('#myForm').bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    "realname": {
                        validators: {
                            notEmpty: true
                        }
                    },
                  "phone": {
                    validators: {
                      notEmpty: true
                    }
                  },
                    "idcard": {
                        validators: {
//                            digits: true,
                            notEmpty: true,
                            remote: {
                                type: "post",
                                delay: 500,
                                url: '${URL_PPPATIENTBASE_VALIDATE_IDCARD}',
                                data: function (validator) {
                                    return {
                                        mobile: validator.getFieldElements('idcard').val(),
                                        exception: '${entity.idcard}'
                                    };
                                },
                                message: '该身份证已存在'
                            }
                        }
                    },
                    "height": {
                        validators: {
                            regexp: {
                                regexp: /^[0-9]+(.[0-9]{1})?$/
                            }
                        }
                    },
                    "weight": {
                        validators: {
                            regexp: {
                                regexp: /^[0-9]+(.[0-9]{1})?$/
                            }
                        }
                    }
                }
            }).on('success.form.bv', function (e) {
                e.preventDefault();
                var _url="";
                if($("#id").val() == null || $("#id").val() == ''){
                    _url =  '${URL_PATIENT_ADDRECARD}';
                }else{
                    _url =  '${URL_PPPATIENTBASE_UPDATE}';
                }
                if( $('#idcard').val().length != 18 ){
                    alert('身份证格式错误')
                    return
                }
                $.ajax({
                    url: _url,
                    type: 'post',
                    data: $('#myForm').serialize(),
                    async: false, //默认为true 异步
                    success: function (data) {
                        console.log(data)
                        var ob=JSON.parse(data)
                        if( !ob.success ){
                            alert(ob.msg)
                            return
                        }else{
                            closeFrame();
                        }
                    }
                });
            });
        }
        //关闭并刷新
        function closeFrame() {
            window.parent.closeModal();
        }
        $('.selectpicker').bind('change',function(){
            if( $('.selectpicker option:selected').length == '0' ){
                $("#diseasesType").selectpicker({
                    noneSelectedText: '请选择人群' //默认显示内容  
                });
            }
        })
        <%--function keep(){--%>
            <%--// 获取输入信息--%>
            <%--var realname = $("#realname").val()--%>
            <%--var gender = $('#gender option:selected') .val()--%>
            <%--var idCard = $("#idcard").val()--%>
            <%--var medicalinsurancenum = $("#medicalinsurancenum").val()--%>
            <%--var phone = $("#phone").val()--%>
            <%--var height = $("#height").val()--%>
            <%--var weight = $("#weight").val()--%>
            <%--if( realname === "" && idCard === "" ){--%>
                <%--alert("请输入完整信息")--%>
            <%--}else{--%>
                <%--$.ajax({--%>
                    <%--url:"${URL_PATIENT_ADDRECARD}",--%>
                    <%--dataType:"json",--%>
                    <%--type:"post",--%>
                    <%--data:{--%>
                        <%--realname : realname,--%>
                        <%--gender : gender,--%>
                        <%--idcard : idCard,--%>
                        <%--medicalinsurancenum : medicalinsurancenum,--%>
                        <%--phone : phone,--%>
                        <%--height : height,--%>
                        <%--weight : --%>
                    <%--},--%>
                    <%--success:function(data){--%>

                    <%--}--%>
                <%--})--%>
            <%--}--%>
        <%--}--%>
    </script>
</head>
<body style="width: 98%">
<div class="header">
    <h1>新增病人信息</h1>
</div>
<form id="myForm" class="form-horizontal" method="post">
    <input type="hidden" id="id" name="id" value="${entity.id}">
    <div class="clearfix">
        <div class="form-group mg">
            <label class="control-label">姓名</label>
            <input type="text" id="realname" name="realname" class="form-control required" value="${entity.realname}">
            <span style="color:red;" class="remark">!</span>
        </div>
        <%--<div class="form-group">--%>
            <%--<label class="control-label">性别</label>--%>
            <%--<select id="gender" name="gender" class="form-control">--%>
                <%--<medi:configOpt name="gender2" key="${entity.gender}"/>--%>
            <%--</select>--%>
        <%--</div>--%>
        <div class="form-group">
            <label class="control-label" style="margin-right:8px;">身份证</label>
            <input type="text" id="idcard" name="idcard" class="form-control required" value="${entity.idcard}">
            <span style="color:red;" class="remark">!</span>
        </div>
        <div class="form-group mg">
            <label class="control-label">医保号</label>
            <input type="text" id="medicalinsurancenum" name="medicalinsurancenum" class="form-control mgr" value="${entity.medicalinsurancenum}">
        </div>
        <div class="form-group">
            <label class="control-label">手机号码</label>
            <input type="text" id="phone" name="phone" class="form-control required" value="${entity.phone}">
            <span style="color:red;" class="remark">!</span>
        </div>
        <div class="form-group mg">
            <label class="control-label">身高</label>
            <input type="text" id="height" name="height" class="form-control mgr" value="${entity.height}">
        </div>
        <div class="form-group ">
            <label class="control-label">体重</label>
            <input type="text" id="weight" name="weight" class="form-control" value="${entity.weight}">
        </div>
        <div class="form-group mg">
            <label class="control-label">备注</label>
            <input type="text" id="remark" name="remark" class="form-control mgr" value="${entity.remark}">
        </div>
        <div class="form-group ">
            <label for="diseasesType"  class="control-label">疾病分类</label>
            <select name="diseasesType" class="selectpicker form-control"  id="diseasesType" multiple >
                <option value="1">高血压人群</option>
                <option value="2">糖尿病人群</option>
                <option value="3">高血脂人群</option>
                <option value="4">骨松人群</option>
                <option value="5">失智老人人群</option>
            </select>
        </div>
    </div>
    <div class="form-group submitBtn">
        <button type="button" class="btn" data-dismiss="modal" id="closeModalButt" onclick="closeFrame()">
            关闭
        </button>
        <button type="submit" class="btn">保存</button>
    </div>
</form>
</body>
</html>
